package com.lzm.ydpt.mvp.presenterimpl;

import com.byt.framlib.basemvp.BasePresenter;
import com.byt.framlib.basemvp.basebean.BaseResponseBean;
import com.byt.framlib.basemvp.exception.ApiException;
import com.byt.framlib.basemvp.listener.OnLoadingErrorListener;
import com.byt.framlib.basemvp.listener.OnLoadingProgressListener;
import com.google.gson.JsonObject;
import com.lzm.ydpt.module.mall.activity.DiscountActionActivity;
import com.lzm.ydpt.mvp.api.ProgressSubscriber;
import com.lzm.ydpt.mvp.contract.DiscountActionContract;
import com.lzm.ydpt.mvp.modelimpl.DiscountActionModelImpl;

/**
 * 类名称：DiscountActionPresenterImpl
 * 类描述：代理实现
 */
public class DiscountActionPresenterImpl extends BasePresenter implements DiscountActionContract.Presenter {

    private DiscountActionContract.View mView;
    private DiscountActionContract.Model mModel;

    public DiscountActionPresenterImpl(DiscountActionActivity context) {
        super(context);
        this.mView = context;
        this.mModel = new DiscountActionModelImpl();
    }

    @Override
    public void onDiscountAction() {
        mManager.http(mModel.onDiscountAction(), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<JsonObject>() {
            @Override
            public void onLoadingResult(BaseResponseBean<JsonObject> entity) {
                mView.onDiscountAction();
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showMessage(e.getDisplayMessage(), method);
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showMessage(entity.getMessage(), method);
            }
        }, "onDiscountAction"));
    }
}